package com.cloudbroker.bcs.platform.dav.middle.extservice.uf30.impl;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.csvc.uf30.api.t2service.CifT2Service;
import com.cloudbroker.bcs.csvc.uf30.api.t2service.FundT2Service;
import com.cloudbroker.bcs.csvc.uf30.api.t2service.VirFundT2Service;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.AccountBindForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.AccountOpenAndBindForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.AccountQryForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.GoldCoinChangeForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.GoldcoinJourComQryForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.GoldcoinJourQryForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.GoldcoinRechangeOffForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.GoldcoinSysRechangeForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.GoldcoinTransForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.MobileModForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.OrgTransStatusQryForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.OutcashPayForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.PaybkTransferQryForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.PointBalanceForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.PointChangeForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.PointJourQryForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.base.CifForm;
import com.cloudbroker.bcs.csvc.uf30.api.vo.request.base.UF30Form;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.CifBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.GoldcoinBalanceQryBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.GoldcoinComBalanceQryBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.GoldcoinJourComQryBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.GoldcoinJourQryBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.OrgTransStatusQryBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.PaybkTransferQryBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.PointBalanceQryBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.PointChangeBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.PointJourQryBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.TransIdBackVo;
import com.cloudbroker.bcs.csvc.uf30.api.vo.response.base.UF30BackVo;
import com.cloudbroker.bcs.platform.dav.middle.extservice.uf30.UF30Service;

/**
 * Created by xuyn15828 on 2016/3/21.
 */
@Service
public class UF30ServiceImpl implements UF30Service {
    
    private static final Logger logger = LoggerFactory.getLogger(UF30ServiceImpl.class);
    @Resource
    private CifT2Service cifServiceT2;
    @Resource
    private FundT2Service fundServiceT2;
    @Resource
    private VirFundT2Service virFundServiceT2;
    
    @Override
    public CifBackVo cifAccountQry(AccountQryForm param) {
        return cifServiceT2.cifAccountQry(param);
    }
    
    @Override
    public CifBackVo cifAccountBind(AccountBindForm param) {
        return cifServiceT2.cifAccountBind(param);
    }
    
    @Override
    public CifBackVo cifAccountOpenAndBind(AccountOpenAndBindForm param) {
        return cifServiceT2.cifAccountOpenAndBind(param);
    }
    
    @Override
    public UF30BackVo cifMobileMod(MobileModForm param) {
        return cifServiceT2.cifMobileMod(param);
    }
    
    @Override
    public OrgTransStatusQryBackVo orgTransStatusQry(OrgTransStatusQryForm param) {
        return fundServiceT2.orgTransStatusQry(param);
    }
    
    @Override
    public PaybkTransferQryBackVo payBkTransferQry(PaybkTransferQryForm param) {
        return fundServiceT2.payBkTransferQry(param);
    }
    
    @Override
    public TransIdBackVo outcashPay(OutcashPayForm param) {
        return fundServiceT2.outcashPay(param);
    }
    
    @Override
    public TransIdBackVo goldcoinChange(GoldCoinChangeForm param) {
        return virFundServiceT2.goldcoinChange(param);
    }
    
    @Override
    public TransIdBackVo goldcoinRechangeOff(GoldcoinRechangeOffForm param) {
        return virFundServiceT2.goldcoinRechangeOff(param);
    }
    
    @Override
    public TransIdBackVo goldcoinTrans(GoldcoinTransForm param) {
        return virFundServiceT2.goldcoinTrans(param);
    }
    
    @Override
    public GoldcoinJourQryBackVo goldcoinJourQry(GoldcoinJourQryForm param) {
        return virFundServiceT2.goldcoinJourQry(param);
    }
    
    @Override
    public GoldcoinBalanceQryBackVo goldcoinBalanceQry(CifForm param) {
        return virFundServiceT2.goldcoinBalanceQry(param);
    }
    
    @Override
    public TransIdBackVo goldcoinSystemChange(GoldcoinSysRechangeForm param) {
        return virFundServiceT2.goldcoinSystemChange(param);
    }
    
    @Override
    public GoldcoinJourComQryBackVo goldcoinJourComQry(GoldcoinJourComQryForm param) {
        return virFundServiceT2.goldcoinJourComQry(param);
    }
    
    @Override
    public GoldcoinComBalanceQryBackVo goldcoinComBalanceQry(UF30Form param) {
        return virFundServiceT2.goldcoinComBalanceQry(param);
    }
    
    @Override
    public String ucReg(String mobile_tel, String real_name, String pwd, String businessAccount) {
        
        String cif_id = null;
        // 查询用户是否已经注册
        AccountQryForm form = new AccountQryForm();
        form.setMobile_tel(mobile_tel);
        form.setOpen_way("5");
        form.setBusiaccount(businessAccount);
        CifBackVo cifBackVo = this.cifAccountQry(form);
        if (!VOUtil.isSuccess(cifBackVo)) {
            return null;
        }
        cif_id = String.valueOf(cifBackVo.getCif_id());
        // 未注册
        if ("0".equals(cif_id)) {
            // 调用用户中心业务账号绑定
            AccountOpenAndBindForm bindForm = new AccountOpenAndBindForm();
            bindForm.setMobile_tel(mobile_tel);
            bindForm.setReal_name(real_name);
            bindForm.setLogin_password(pwd);
            bindForm.setOpen_way("5");
            bindForm.setBusiaccount(businessAccount);
            cifBackVo = this.cifAccountOpenAndBind(bindForm);
            if (!VOUtil.isSuccess(cifBackVo)) {
                logger.error("UF30注册失败！" + cifBackVo.toString());
                cifBackVo = this.cifAccountQry(form);
                if (!VOUtil.isSuccess(cifBackVo)) {
                    return null;
                }
                cif_id = String.valueOf(cifBackVo.getCif_id());
                if (!"0".equals(cif_id)) {
                    return cif_id;
                }
                return null;
            } else {
                cif_id = String.valueOf(cifBackVo.getCif_id());
            }
        }
        return cif_id;
        
    }

    @Override
    public PointJourQryBackVo pointJourQry(PointJourQryForm param) {
        return virFundServiceT2.pointJourQry(param);
    }

    @Override
    public PointBalanceQryBackVo pointQry(PointBalanceForm param) {
        return virFundServiceT2.pointQry(param);
    }

    @Override
    public PointChangeBackVo pointRecharge(PointChangeForm param) {
        return virFundServiceT2.pointRecharge(param);
    }

    @Override
    public PointChangeBackVo pointConsume(PointChangeForm param) {
        return virFundServiceT2.pointConsume(param);
    }
}
